﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ScriptManager.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Scriptmanager - random numbers</title>
    <style type="text/css">
    body
    {
        margin:0;
        padding:0;
        text-align:center;
        border-top:8px solid #ccc;
        font-family:Georgia;
        font-size:80px;
    }
    #wrapper
    {
        width:100px;
        text-align:left;
        margin:0 auto;
    }
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            var i = 0;
            var timer = setInterval(function () {

                PageMethods.GetRandomNumber(1, 100, function (res) {
                    //sucess
                    //alert(res);
                    $("#uiNbrs").append("<div class='nbr'>" + res + "</div>");
                }, function () {
                    //fail
                    $("#uiNbrs").append("<div class='nbr'>failed to get a random number...</div>");
                    clearInterval(timer);
                });


                /*
                var service = new ScriptManager.RandomNumberService();
                service.GetANumber(1, 100, function (res) {
                //sucess
                var n = res.toString();
                $("#uiNbrs").append(n + "<br />");
                }, function () {
                //fail
                });
                */

                i++;
                if (i >= 10) {
                    $(".nbr:first-child").remove();

                    //clearInterval(timer);
                }


            }, 500);
        });
    </script>
</head>
<body>
<div id="wrapper">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="uiScriptManager" runat="server" EnablePageMethods="true">
        <Services>
            <asp:ServiceReference Path="~/RandomNumberService.asmx" />
        </Services>
    </asp:ScriptManager>
    <div id="uiNbrs"></div>
    </form>
</div>
</body>
</html>
